Skip to content

Copy nonlinear fit input arrays into the cache struct#117

Open
JamesWrigley wants to merge 1 commit into
masterfrom
caches
Open

Copy nonlinear fit input arrays into the cache struct#117
JamesWrigley wants to merge 1 commit into
masterfrom
caches

Conversation

@JamesWrigley

Copy link
Copy Markdown
Member

So that we don't accidentally overwrite the input when using the caches directly and calling reinit!() on them.

Note that the code already makes a copy of u when creating the solution, so that's not aliased. I considered making that aliasing as well but decided it would be too confusing since I could definitely see situations where people call reinit!() + solve!() in a loop and push u to an array or something.

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

So that we don't accidentally overwrite the input when using the caches directly
and calling `reinit!()` on them.
@JamesWrigley JamesWrigley self-assigned this Jul 7, 2026
Comment thread docs/src/_changelog.md
Comment on lines +12 to +17
### Fixed
- Changed the solver for [`NonlinearCurveFitProblem`](@ref) to make copies of
the input arrays into its internal cache so that the original input arrays
won't be overwritten if `reinit!(cache; x, y, sigma)` is called
([#117]). Doing one-off solves will incur extra allocations due to the copy,
reusing the cache remains as efficient as before.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably us an AbstractAliasSpecifier with the alias kwarg, i.e. the SciMLBase aliasing interface, for this package to control this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants